﻿using DXApplicationTangche.UC.抖音出入库.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.抖音出入库
{
    public partial class Form抖音sku一览 : DevExpress.XtraEditors.XtraForm
    {
        private List<DouyinSkuDao> douyinSkuDaos = new List<DouyinSkuDao>();
        public Form抖音sku一览()
        {
            InitializeComponent();
            this.刷新();
        }
        private void 刷新()
        {
            this.douyinSkuDaos = 抖音Service.getDouyinSKU();
            this.gridControl抖音sku一览.DataSource = this.douyinSkuDaos;
            this.gridView抖音sku一览.RefreshData();
            this.gridView抖音sku一览.ExpandAllGroups();
        }

        private void 保存成衣参考码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                String skuId = this.gridView抖音sku一览.GetRowCellValue(this.gridView抖音sku一览.FocusedRowHandle, "skuId").ToString();
                foreach (DouyinSkuDao item in this.douyinSkuDaos)
                {
                    if (skuId.Equals(item.skuId))
                    {
                        new Form抖音保存成衣参考码(item).ShowDialog();
                        break;
                    }
                }
                this.刷新();
            }
            catch 
            {
                return;
            }
        }

        private void gridView抖音sku一览_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (e.Column.Name == "gridColumn成衣条码")
            {
                if (e.CellValue == null)
                {
                    e.Appearance.BackColor = Color.OrangeRed;
                }
                e.Appearance.BackColor = Color.LightGreen;
            }
        }

        /// <summary>
        /// csv导入抖音sku
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void simpleButtonCSV导入抖音sku_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "csv|*.csv";
            ofd.Title = "请选择csv文件";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                //  csv导入
                String re = 抖音Service.saveDouyinSku(ofd.FileName);
                MessageBox.Show("csv上传成功");
                this.刷新();
            }
        }
    }
}
